package com.bw.patrol.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.alibaba.android.arouter.launcher.ARouter
import com.bumptech.glide.Glide
import com.bw.base.constants.RoutePath
import com.bw.image.GlideImageLoader
import com.bw.patrol.R
import com.bw.patrol.click.onClick
import com.bw.patrol.databinding.PatroItemBinding
import com.bw.patrol.entity.PatrolEntity
import java.util.zip.Inflater

/**
 * Author :
 * Created by skypoe on 2025/5/13.
 * Description:
 */
class PatroAdapter(private val list:MutableList<PatrolEntity>) : RecyclerView.Adapter<PatroAdapter.PatroViewHolder>() {


    inner class PatroViewHolder(val binding:PatroItemBinding):RecyclerView.ViewHolder(binding.root)

    private var onClick:onClick ? = null


    fun serOnItemClick(listener:onClick){
        this.onClick=listener
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PatroViewHolder {
        val binding=PatroItemBinding.inflate(LayoutInflater.from(parent.context),parent, false)
        return PatroViewHolder(binding)
    }

    override fun getItemCount(): Int {
        return list.size
    }

    override fun onBindViewHolder(holder: PatroViewHolder, position: Int) {
        val patro=list[position]
        holder.binding.patro=patro

        Glide.with(holder.itemView.context).load(R.drawable.doro).circleCrop().into( holder.binding.heard)

        holder.binding.edit.setOnClickListener {
            onClick?.setOnClick(position)
        }

        holder.binding.patrol.setOnClickListener {
            ARouter.getInstance().build(RoutePath.PATH_PATROL_NFC).navigation()
        }
    }


}